﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace PostgreSQL.Models
{
    public partial class dbembedContext : DbContext
    {
        public dbembedContext()
        {
        }

        public dbembedContext(DbContextOptions<dbembedContext> options)
            : base(options)
        {
        }

        public virtual DbSet<AlembicVersion> AlembicVersions { get; set; }
        public virtual DbSet<Group> Groups { get; set; }
        public virtual DbSet<GroupsPermission> GroupsPermissions { get; set; }
        public virtual DbSet<GroupsUser> GroupsUsers { get; set; }
        public virtual DbSet<Irdatum> Irdata { get; set; }
        public virtual DbSet<Permission> Permissions { get; set; }
        public virtual DbSet<User> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseNpgsql("Host=192.168.1.99;Port=5433;Database=dbembed;Username=dbuser;Password=bz_23960103");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "en_US.UTF-8");

            modelBuilder.Entity<AlembicVersion>(entity =>
            {
                entity.HasKey(e => e.VersionNum)
                    .HasName("alembic_version_pkc");

                entity.ToTable("alembic_version");

                entity.Property(e => e.VersionNum)
                    .HasMaxLength(32)
                    .HasColumnName("version_num");
            });

            modelBuilder.Entity<Group>(entity =>
            {
                entity.ToTable("groups");

                entity.HasIndex(e => e.Name, "groups_name_key")
                    .IsUnique();

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.IsDeleted).HasColumnName("is_deleted");

                entity.Property(e => e.Name)
                    .IsRequired()
                    .HasMaxLength(20)
                    .HasColumnName("name");
            });

            modelBuilder.Entity<GroupsPermission>(entity =>
            {
                entity.HasNoKey();

                entity.ToTable("groups_permissions");

                entity.Property(e => e.GroupId).HasColumnName("group_id");

                entity.Property(e => e.PermissionId).HasColumnName("permission_id");

                entity.HasOne(d => d.Group)
                    .WithMany()
                    .HasForeignKey(d => d.GroupId)
                    .HasConstraintName("groups_permissions_group_id_fkey");

                entity.HasOne(d => d.Permission)
                    .WithMany()
                    .HasForeignKey(d => d.PermissionId)
                    .HasConstraintName("groups_permissions_permission_id_fkey");
            });

            modelBuilder.Entity<GroupsUser>(entity =>
            {
                entity.HasNoKey();

                entity.ToTable("groups_users");

                entity.Property(e => e.GroupsId).HasColumnName("groups_id");

                entity.Property(e => e.UsersId).HasColumnName("users_id");

                entity.HasOne(d => d.Groups)
                    .WithMany()
                    .HasForeignKey(d => d.GroupsId)
                    .HasConstraintName("groups_users_groups_id_fkey");

                entity.HasOne(d => d.Users)
                    .WithMany()
                    .HasForeignKey(d => d.UsersId)
                    .HasConstraintName("groups_users_users_id_fkey");
            });

            modelBuilder.Entity<Irdatum>(entity =>
            {
                entity.ToTable("irdata");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CreatedOn).HasColumnName("created_on");

                entity.Property(e => e.DataIr)
                    .IsRequired()
                    .HasColumnName("data_ir");

                entity.Property(e => e.IsDeleted).HasColumnName("is_deleted");

                entity.Property(e => e.MaxTemp).HasColumnName("max_temp");
            });

            modelBuilder.Entity<Permission>(entity =>
            {
                entity.ToTable("permissions");

                entity.HasIndex(e => e.Text, "permissions_text_key")
                    .IsUnique();

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.IsDeleted).HasColumnName("is_deleted");

                entity.Property(e => e.Text)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("text");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.ToTable("users");

                entity.HasIndex(e => e.Email, "ix_users_email")
                    .IsUnique();

                entity.HasIndex(e => e.Username, "ix_users_username")
                    .IsUnique();

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CreatedOn).HasColumnName("created_on");

                entity.Property(e => e.Email)
                    .IsRequired()
                    .HasMaxLength(120)
                    .HasColumnName("email");

                entity.Property(e => e.IsDeleted).HasColumnName("is_deleted");

                entity.Property(e => e.Nickname)
                    .HasMaxLength(20)
                    .HasColumnName("nickname");

                entity.Property(e => e.PasswordHash)
                    .HasMaxLength(128)
                    .HasColumnName("password_hash");

                entity.Property(e => e.PermissionTmp)
                    .HasMaxLength(20)
                    .HasColumnName("permission_tmp");

                entity.Property(e => e.Username)
                    .IsRequired()
                    .HasMaxLength(64)
                    .HasColumnName("username");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
